package yxy.game.pm2.command.refer;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.bean.PlayerBean;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.MainMessage;

/** null 查询角色创建升级时间 */
@MessageType(proto = Command.ReferPlayerCreateUpgradeTime, classtype = MainMessage.ReferPlayerCreateUpgradeTimeRequest.class)
public class CMD_ReferPlayerCreateUpgradeTime extends Command<MainMessage.ReferPlayerCreateUpgradeTimeRequest> {

	@Override
	public void execute(MessageSource messageSource, MainMessage.ReferPlayerCreateUpgradeTimeRequest request) {
		String playerCode = messageSource.getTag();

		MainMessage.ReferPlayerCreateUpgradeTimeResponse.Builder response = MainMessage.ReferPlayerCreateUpgradeTimeResponse.newBuilder();

		PlayerBean playerBean = PlayerBean.get(playerCode);
		response.setCreateTime(playerBean.getCreateTime().getMillis());
		response.setUpgradeTime(playerBean.getUpgradeTime().getMillis());

		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, MainMessage.ReferPlayerCreateUpgradeTimeResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}